package com.kcyu.egoodsmapbackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kcyu.egoodsmapbackend.entity.Goods;
import com.kcyu.egoodsmapbackend.entity.WebPage;
import com.kcyu.egoodsmapbackend.mapper.GoodsMapper;
import com.kcyu.egoodsmapbackend.service.IGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kcyu
 * @since 2025-03-03
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Override
    public WebPage<Goods> page(WebPage<Goods> page) {
        Goods queryCondition = page.getQueryCondition();
        QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
        goodsQueryWrapper.lambda()
                .eq(queryCondition.getIsPresale() != null, Goods::getIsPresale, queryCondition.getIsPresale())
                .orderByDesc(Goods::getCreateTime);
        return this.baseMapper.selectPage(page, goodsQueryWrapper);
    }
}
